﻿#region zh-CHS 2006 - 2010 DemoSoft 团队 | en 2006-2010 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the MMOSE(Massively Multiplayer Online Server Engine) for .NET.
//
//                              2006-2010 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using Demo.Mmose.Core.Common.SafeCollections;
#endregion

namespace Demo.Mmose.Core.Entity.Suit.Quest
{
    /// <summary>
    /// 任务目标的集合（一般用于NPC身上）
    /// </summary>
    public class QuestObjectiveCollection : IEnumerable<QuestObjective>
    {
        #region zh-CHS 共有方法 | en Public Methods

        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private SafeDictionary<long, QuestObjective> m_QuestObjectiveDictionary = new SafeDictionary<long, QuestObjective>();
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="baseTaxiNode"></param>
        public void AddQuestObjective( long questObjectiveId, QuestObjective questObjective )
        {
            if ( questObjective == null )
                throw new ArgumentNullException( "questObjective", "QuestObjectiveCollection.AddQuestObjective(...) - questObjective == null error!" );

            m_QuestObjectiveDictionary.Add( questObjectiveId, questObjective );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public QuestObjective FindQuestObjectiveOnId( long questObjectiveId )
        {
            return m_QuestObjectiveDictionary.GetValue( questObjectiveId );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public void RemoveQuest( long questObjectiveId )
        {
            m_QuestObjectiveDictionary.Remove( questObjectiveId );
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="iQuestId"></param>
        public void Clear()
        {
            m_QuestObjectiveDictionary.Clear();
        }

        /// <summary>
        /// 
        /// </summary>
        public QuestObjective[] ToArray()
        {
            return m_QuestObjectiveDictionary.ToArrayValues();
        }

        /// <summary>
        /// 
        /// </summary>
        public IEnumerator<QuestObjectiveT> ToArray<QuestObjectiveT>() where QuestObjectiveT : QuestObjective
        {
            QuestObjective[] tempArray = m_QuestObjectiveDictionary.ToArrayValues();
            if ( tempArray == null )
                yield break;

            for ( int iIndex = 0; iIndex < tempArray.Length; iIndex++ )
            {
                QuestObjectiveT questObjective = tempArray[iIndex] as QuestObjectiveT;
                if ( questObjective == null )
                    continue;
                else
                    yield return questObjective;
            }
        }

        #endregion

        #region zh-CHS 接口实现 | en Interface Implementation
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator<QuestObjective> GetEnumerator()
        {
            QuestObjective[] tempArray = this.ToArray();
            if ( tempArray == null )
                yield break;

            for ( int iIndex = 0; iIndex < tempArray.Length; iIndex++ )
                yield return tempArray[iIndex];
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
        #endregion

    }

}
#endregion